/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.markiewb.netbeans.plugin.savewithsaveactions;

final class SaveactionsPanel extends javax.swing.JPanel {

    private final SaveactionsOptionsPanelController controller;

    SaveactionsPanel(SaveactionsOptionsPanelController controller) {
        this.controller = controller;
        initComponents();
        // TODO listen to changes in form fields and call controller.changed()
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelNote1 = new javax.swing.JLabel();
        labelNote2 = new javax.swing.JLabel();
        cbFixImports = new javax.swing.JCheckBox();
        txtFixImports = new javax.swing.JTextField();
        cbFormat = new javax.swing.JCheckBox();
        txtFormat = new javax.swing.JTextField();
        cbSave = new javax.swing.JCheckBox();
        txtSave = new javax.swing.JTextField();
        btnResetToDefaults = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnShowAllActions = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.jPanel1.border.title"))); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(labelNote1, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.labelNote1.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(labelNote2, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.labelNote2.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(cbFixImports, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.cbFixImports.text")); // NOI18N
        cbFixImports.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cbFixImportsStateChanged(evt);
            }
        });
        cbFixImports.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbFixImportsActionPerformed(evt);
            }
        });

        txtFixImports.setText(org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.txtFixImports.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(cbFormat, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.cbFormat.text")); // NOI18N
        cbFormat.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                cbFormatStateChanged(evt);
            }
        });
        cbFormat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbFormatActionPerformed(evt);
            }
        });

        txtFormat.setText(org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.txtFormat.text")); // NOI18N
        txtFormat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFormatActionPerformed(evt);
            }
        });

        cbSave.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(cbSave, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.cbSave.text")); // NOI18N
        cbSave.setEnabled(false);
        cbSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbSaveActionPerformed(evt);
            }
        });

        txtSave.setText(org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.txtSave.text")); // NOI18N
        txtSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSaveActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(btnResetToDefaults, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.btnResetToDefaults.text")); // NOI18N
        btnResetToDefaults.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetToDefaultsActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.jLabel1.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(btnShowAllActions, org.openide.util.NbBundle.getMessage(SaveactionsPanel.class, "SaveactionsPanel.btnShowAllActions.text")); // NOI18N
        btnShowAllActions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowAllActionsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnShowAllActions)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnResetToDefaults))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbFixImports)
                            .addComponent(cbFormat)
                            .addComponent(cbSave))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtSave)
                            .addComponent(txtFixImports)
                            .addComponent(txtFormat)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(95, 95, 95)
                                .addComponent(jLabel1))
                            .addComponent(labelNote2)
                            .addComponent(labelNote1))
                        .addGap(0, 101, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(labelNote1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelNote2)
                .addGap(16, 16, 16)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFixImports, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbFixImports))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbFormat)
                    .addComponent(txtFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbSave)
                    .addComponent(txtSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnResetToDefaults)
                    .addComponent(btnShowAllActions)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cbFixImportsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFixImportsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbFixImportsActionPerformed

    private void cbFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFormatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbFormatActionPerformed

    private void initGUIFromOptions() {
        cbFixImports.setSelected(options.fiximportActionEnabled);
        cbFormat.setSelected(options.formatActionEnabled);
        txtFixImports.setText(options.fiximportAction);
        txtFormat.setText(options.formatAction);
        txtSave.setText(options.saveAction);
    }

    private void txtFormatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFormatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtFormatActionPerformed

    private void cbSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSaveActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbSaveActionPerformed

    private void txtSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSaveActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSaveActionPerformed

    private void cbFixImportsStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cbFixImportsStateChanged
        txtFixImports.setEnabled(cbFixImports.isSelected());
    }//GEN-LAST:event_cbFixImportsStateChanged

    private void btnResetToDefaultsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetToDefaultsActionPerformed

        options.reset();
        initGUIFromOptions();

    }//GEN-LAST:event_btnResetToDefaultsActionPerformed

    private void cbFormatStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_cbFormatStateChanged
        txtFormat.setEnabled(cbFormat.isSelected());
    }//GEN-LAST:event_cbFormatStateChanged

    private void btnShowAllActionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowAllActionsActionPerformed

        //execute action
        new ShowAllActionsAction().actionPerformed(evt);
    }//GEN-LAST:event_btnShowAllActionsActionPerformed
    private Options options = null;

    void load() {
        options = new Options();
        options.load();
        initGUIFromOptions();
    }

    void store() {

        options.fiximportActionEnabled = cbFixImports.isSelected();
        options.formatActionEnabled = cbFormat.isSelected();
        options.fiximportAction = txtFixImports.getText();
        options.formatAction = txtFormat.getText();
        options.saveAction = txtSave.getText();

        options.save();
    }

    boolean valid() {
        // TODO check whether form is consistent and complete
        return true;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnResetToDefaults;
    private javax.swing.JButton btnShowAllActions;
    private javax.swing.JCheckBox cbFixImports;
    private javax.swing.JCheckBox cbFormat;
    private javax.swing.JCheckBox cbSave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelNote1;
    private javax.swing.JLabel labelNote2;
    private javax.swing.JTextField txtFixImports;
    private javax.swing.JTextField txtFormat;
    private javax.swing.JTextField txtSave;
    // End of variables declaration//GEN-END:variables
}
